﻿using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using BLL.Services.Users;
using Web.Infrastructure.Models;

namespace Web.Models.Account
{
    public class AccountModel : BaseModel
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="AccountModel"/> class.
        /// </summary>
        /// <param name="user">The user.</param>
        public AccountModel(User user)
        {
            ToModel(user, this);
            UserEmail = user.Email;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="AccountModel"/> class.
        /// </summary>
        public AccountModel()
        {
        }

        [ReadOnly(true)]
        public string UserEmail { get; set; }

        [Compare("ConfirmPassword")]
        [DataType(DataType.Password)]
        public string Password { get; set; }

        [DataType(DataType.Password)]
        public string ConfirmPassword { get; set; }

        public string Name { get; set; }

        public string Surname { get; set; }

        public string City { get; set; }

        [UIHint("Avatar")]
        public string Avatar { get; set; }

        public static User operator +(User user, AccountModel model)
        {
            ToEntity(model, user);
            if (model.Password != null)
            {
                user.SetPassword(model.Password);
            }
            return user;
        }
    }
}